package com.zgis.module.db.runner;

import com.zgis.module.db.service.TableCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 应用启动后加载表数据到 Redis
 * 支持单体架构和微服务架构
 *
 * @author yudao
 */
@Slf4j
@Component
public class TableCacheApplicationRunner implements ApplicationRunner {

    @Resource
    private TableCacheService tableCacheService;

    @Override
    public void run(ApplicationArguments args) {
        log.info("[TableCacheApplicationRunner] 应用启动完成，开始初始化表缓存");
        try {
            tableCacheService.loadAllTablesToCache();
            log.info("[TableCacheApplicationRunner] 表缓存初始化完成");
        } catch (Exception e) {
            log.error("[TableCacheApplicationRunner] 表缓存初始化失败", e);
            // 不抛出异常，避免影响应用启动
        }
    }
}
